package com.b1502.store2.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.b1502.store2.R;
import com.b1502.store2.model.OrderList;
import com.b1502.store2.util.ImageLoaderUtils;
import com.b1502.store2.util.UrlUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * 作者：朱振江 on 2017/3/1 0001 16:57
 * 邮箱：zzjdys@Gmail.com
 * 类用途:
 */


public class OrderGridviewadapter extends BaseAdapter{
    private Context mContext;
    private List<OrderList.ProductsBean> mList;
    private final ImageLoader mImageLoader;
    private final DisplayImageOptions mOptions;


    public OrderGridviewadapter(Context context) {
        mContext = context;
        mImageLoader = ImageLoader.getInstance();
        mOptions = ImageLoaderUtils.initOptions();
    }

    public void setData(List<OrderList.ProductsBean> list) {
        mList = list;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewhord v;
        if (convertView==null)
        {
            v=new viewhord();
            convertView=View.inflate(mContext, R.layout.order_list_gridview_item,null);
            v.mImageView= (ImageView) convertView.findViewById(R.id.order_list_image);
            v.mname= (TextView) convertView.findViewById(R.id.order_list_name);
            v.mmoney= (TextView) convertView.findViewById(R.id.order_list_money);
            convertView.setTag(v);
        }
        else 
        {
            v= (viewhord) convertView.getTag();
        }
        
        v.mname.setText(mList.get(position).getName());
        double price = mList.get(position).getPrice();

        v.mmoney.setText("￥:"+price);

        String imageUrl = mList.get(position).getImageUrl();
        String imageUrl1 = UrlUtil.getImageUrl(imageUrl);

        mImageLoader.displayImage(imageUrl1,v.mImageView,mOptions);
        return convertView;
    }
    
    class viewhord
    {
        ImageView mImageView;
        TextView mname,mmoney;
    }
    
}
